﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">

    protected void BtnCreateCatalog_Click(object sender, EventArgs e)
    {
        Response.Redirect("CreateNetDiskCatalog.aspx");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            this.DataList_DataTable();
        }
    }

    private void DataList_DataTable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("NetDiskCatalogId", typeof(string));
        dt.Columns.Add("NetDiskCatalogName", typeof(string));
        dt.Columns.Add("NetDiskCatalogPath", typeof(string));
        dt.Columns.Add("NetDiskCatalogPcpNames", typeof(string));
        dt.Columns.Add("NetDiskCatalogPcps", typeof(string));
        NetDisktbServices ndService = new NetDisktbServices();
        List<NetDisktb> list = ndService.findAll();
        if(list != null && list.Count > 0)
        {
            foreach(NetDisktb nd in list)
            {
                DataRow dr = dt.NewRow();
                dr["NetDiskCatalogId"] = nd.NetDiskCatalogId.ToString();
                dr["NetDiskCatalogName"] = nd.NetDiskCatalogName;
                dr["NetDiskCatalogPath"] = nd.NetDiskCatalogPath;
                dr["NetDiskCatalogPcpNames"] = nd.PcpNames;
                dr["NetDiskCatalogPcps"] = nd.Pcps;
                dt.Rows.Add(dr);
            }
        }
        if(dt.Rows.Count > 0)
        {
            this.DataList1.DataSource = dt.DefaultView;
        }
        else
        {
            this.DataList1.DataSource = null;
        }
        this.DataList1.DataBind();
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string ndid = ((HtmlInputHidden) e.Item.FindControl("HidNdId")).Value;
            string pcps = ((HtmlInputHidden) e.Item.FindControl("HidNdPcps")).Value;
            string ndPath = ((HtmlInputHidden) e.Item.FindControl("HidNdPath")).Value;
            ((LinkButton) e.Item.FindControl("LbtEdit")).Attributes.Add("nd_id", ndid);
            ((LinkButton) e.Item.FindControl("LbtEdit")).Attributes.Add("nd_pcps", pcps);
            ((LinkButton) e.Item.FindControl("LbtDel")).Attributes.Add("nd_id", ndid);
            ((LinkButton) e.Item.FindControl("LbtDel")).Attributes.Add("onclick", "return confirm('您确定删除此目录信息吗？')");
            ((LinkButton) e.Item.FindControl("LbtDel")).Attributes.Add("nd_p", ndPath);
            ((LinkButton) e.Item.FindControl("LbtEditP")).Attributes.Add("nd_id", ndid);
        }
    }

    protected void LbtEdit_Click(object sender, EventArgs e)
    {
        string ndid = ((LinkButton) sender).Attributes["nd_id"];
        Response.Redirect("NetDiskCatalogEdit.aspx?nd_id=" + ndid);
    }

    protected void LbtDel_Click(object sender, EventArgs e)
    {
        int ndid = int.Parse(((LinkButton) sender).Attributes["nd_id"]);
        string ndPath = ((LinkButton) sender).Attributes["nd_p"];
        NetDisktbServices ndService = new NetDisktbServices();
        ndService.DelCatalogInfoById(ndid);
        DirectoryInfo dirInfo = new DirectoryInfo(ndPath);
        if(dirInfo.Exists)
        {
            dirInfo.Delete(true);
        }
        this.DataList_DataTable();
    }

    protected void LbtEditP_Click(object sender, EventArgs e)
    {
        string ndid = ((LinkButton) sender).Attributes["nd_id"];
        Response.Redirect("NetDiskCatalogOpUserEdit.aspx?nd_id=" + ndid);
    }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <link rel="Stylesheet" type="text/css" href="../../Styles/right_style.css" />
    <script type="text/javascript" src="../../Scripts/jquery.ui/js/jquery.js"></script>
	
    <style type="text/css">
        <!--
        html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
        scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
        -->
    </style>	

</head>
<body>
    <form id="form1" runat="server">
            <div class="sub_right_top">
  <div class="hdm_header" >
    <div class="tb1_on"><h2 class="h2_icon">网络硬盘设置</h2></div>

    <div class="clear"></div>
  </div>
  <div class="hdm_footer">
   <div class="fabu_gg_title">网络硬盘</div>
   <div class="new_ggtz">
      <asp:Button ID="BtnCreateCatalog" runat="server" Text="创建共享目录" OnClick="BtnCreateCatalog_Click" />
    </div>   
    <div style="height:10px;"></div>            
    <asp:Repeater ID="DataList1" runat="server"  OnItemDataBound="DataList1_ItemDataBound">
                            <HeaderTemplate>
                                <table width="97%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse; ">
                                     <tr  bgcolor="#e4f1fd">
                                    <td width="160" align="center">共享目录名称</td>
                                    <td align="center">共享目录路径</td>
                                    <td width="80" align="center">目录开放范围</td>
                                    <td width="132" align="center">共享目录操作</td>
                                  </tr>

                            </HeaderTemplate>
                            
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <asp:Label ID="Label5" runat="server" Text='<%# Eval("NetDiskCatalogName") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="Label6" runat="server" Text='<%# Eval("NetDiskCatalogPath") %>'></asp:Label></td>
                                    <td>
                                        <asp:Label ID="Label7" runat="server" Text='<%# Eval("NetDiskCatalogPcpNames") %>'></asp:Label></td>
                                    <td>
                                        <asp:LinkButton ID="LbtEdit" runat="server" OnClick="LbtEdit_Click">编辑</asp:LinkButton>
                                        <asp:LinkButton ID="LbtDel" runat="server" OnClick="LbtDel_Click">删除</asp:LinkButton>
                                        <asp:LinkButton ID="LbtEditP" runat="server" OnClick="LbtEditP_Click">编辑管理权限</asp:LinkButton>
                                        <input id="HidNdId" runat="server" type="hidden" value='<%# Eval("NetDiskCatalogId") %>' />
                                        <input id="HidNdPcps" runat="server" type="hidden" value='<%# Eval("NetDiskCatalogPcps") %>' />
                                        <input id="HidNdPath" runat="server" type="hidden" value='<%# Eval("NetDiskCatalogPath") %>' />
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>

    <div style="height:20px;"></div>
  </div>
</div>

    </form>
</body>
</html>
